import { createStore } from 'vuex'

export default createStore({
    state: sessionStorage.getItem('state') ? JSON.parse(sessionStorage.getItem('state')) : {
        tabs_list: [],
        user_info: {},
        user_list: [], // 系统用户俩表
        role_list: [],// 权限 树 展示树结构使用
        role_arr: [],// 权限组 校验时使用
        isCollapse: false, // 网页全屏 F11
        is_top_menu: false, // 是否第一个菜单
        hidden_tabs: true,
        is_all_page: false, // 页面全屏
        enterprise_list: [],
        product_list: [],
        customForm_right_list: [],// 自定义表单 勾选权限
        condition_setup_list: [],// 自定义表单 勾选条件
    },
    mutations: {
        // 进行数据更新，改变数据状态
        add_tabs_list(state, e) {
            state.tabs_list.push(e)
            state.tabs_list.forEach(element => {
                element.is_active = false
            })
            state.tabs_list.at(-1).is_active = true
        },
        remove_tabs_list(state, e) {
            if (state.tabs_list.length == 1) {
                return
            }
            if (e.close_self) {
                if (state.tabs_list[e.index].is_active) {
                    state.tabs_list[e.index - 1].is_active = true
                }
            }
            state.tabs_list.splice(e.index, e.length)
        },
        select_tabs_list(state, e) {
            state.tabs_list.forEach((item) => {
                item.is_active = false
            })
            state.tabs_list[e].is_active = true
        },
        clear_tabs_list(state) {
            state.tabs_list = []
        },
        set_user_info(state, e) {
            state.user_info = e
        },
        set_user_list(state, e) {
            state.user_list = e
        },
        set_role_arr(state, e) {
            state.role_arr = e
        },
        set_role_list(state, e) {
            state.role_list = e
        },
        change_isCollapse(state) {
            state.isCollapse = !state.isCollapse
        },
        change_top_menu(state, e) {
            if (e) {
                state.is_top_menu = false
            } else {
                state.is_top_menu = !state.is_top_menu
            }
        },
        change_hidden_tabs(state) {
            state.hidden_tabs = !state.hidden_tabs
        },
        change_all_page(state) {
            state.is_all_page = !state.is_all_page
        },
        set_enterprise_list(state, e) {
            state.enterprise_list = e
        },
        set_product_list(state, e) {
            state.product_list = e
        },
        set_customForm_right_list(state, e) {
            state.customForm_right_list = e
        },
        clear_customForm_right_list(state) {
            state.customForm_right_list = []
        },
        set_condition_setup_list(state, e) {
            state.condition_setup_list = e
        },
        clear_condition_setup_list(state) {
            state.condition_setup_list = []
        },
    },
    actions: {
        //执行动作，数据请求

    },
    getters: {
        // 获取到最终的数据结果
    }
})
